package br.com.j7.jdesk.persistence.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Version;

import br.com.j7.jdesk.persistence.listener.ServiceSituationListener;

/**
 * Entidade ServiceSituation
 * 
 * @author Edivando Alves
 *
 */
@Entity
@EntityListeners(value={ServiceSituationListener.class})
@NamedQueries( {@NamedQuery(name="serviceSituation", query="select ss from ServicesSituations ss ORDER BY ss.idServiceSituation"), 
				@NamedQuery(name="serviceSituationByCdServiceSituation", query="Select ss from ServicesSituations ss where cdServiceSituation = ?1 AND enterprise = ?2 ORDER BY ss.idServiceSituation"), 
				@NamedQuery(name="serviceSituationByEnterprise", query="Select ss from ServicesSituations ss where enterprise = ?1 ORDER BY ss.idServiceSituation")} )
public class ServicesSituations implements Serializable{
	private static final long serialVersionUID = 1L;
	
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private Integer idServiceSituation;
	
	@JoinColumn(name="idServiceSituation")
	@OneToMany(mappedBy="serviceSituation", cascade=CascadeType.PERSIST)
	private List<Services> services;
	@Column(nullable=true,length=60)
	private String cdServiceSituation;
	@Lob
	@Column(nullable=true)
	private String dsServiceSituation;
	@ManyToOne
	@JoinColumn(name="idEnterprise")
	private Enterprises enterprise;
	
	private String dsPathIcon;
	@Version
	private Integer nrVersion;
	
	@ManyToOne
	@JoinColumn(name="idServiceState")
	private ServicesStates serviceState;
	
	@OneToMany(mappedBy="serviceSituation")
	private List<ServicesLogs> servicesLogs;
	
	public ServicesSituations() {
	}
	
	public ServicesSituations(Integer idServiceSituation,
			String cdServiceSituation) {
		super();
		this.idServiceSituation = idServiceSituation;
		this.cdServiceSituation = cdServiceSituation;
	}

	public ServicesSituations(Integer idServiceSituation){
		this.idServiceSituation = idServiceSituation;
	}

	public Integer getIdServiceSituation() {
		return idServiceSituation;
	}

	public List<Services> getServices() {
		if(services == null){
			services = new ArrayList<>();
		}
		return services;
	}
	
	public void setServices(List<Services> services) {
		this.services = services;
	}
	
	public void setIdServiceSituation(Integer idServiceSituation) {
		this.idServiceSituation = idServiceSituation;
	}

	public String getCdServiceSituation() {
		return cdServiceSituation;
	}

	public void setCdServiceSituation(String cdServiceSituation) {
		this.cdServiceSituation = cdServiceSituation;
	}

	public String getDsServiceSituation() {
		return dsServiceSituation;
	}

	public void setDsServiceSituation(String dsServiceSituation) {
		this.dsServiceSituation = dsServiceSituation;
	}
	
	public Integer getNrVersion() {
		return nrVersion;
	}
	
	public void setNrVersion(Integer nrVersion) {
		this.nrVersion = nrVersion;
	}
	
	public Enterprises getEnterprise() {
		return enterprise;
	}
	
	public void setEnterprise(Enterprises enterprise) {
		this.enterprise = enterprise;
	}
	
	public ServicesStates getServiceState() {
		return serviceState;
	}
	
	public void setServiceState(ServicesStates serviceState) {
		this.serviceState = serviceState;
	}
	
	public String getDsPathIcon() {
		return dsPathIcon;
	}
	
	public void setDsPathIcon(String dsPathIcon) {
		this.dsPathIcon = dsPathIcon;
	}
	
	public ServicesSituations addService(Services service){
		service.setServiceSituation(this);
		getServices().add(service);
		return this;
	}
	
	public void removeServicesSituations(Services service){
		getServices().remove(service);
	}
	
	public List<ServicesLogs> getServicesLogs() {
		return servicesLogs;
	}
	
	public void setServicesLogs(List<ServicesLogs> servicesLogs) {
		this.servicesLogs = servicesLogs;
	}
	
	@Override
	public int hashCode() {
		return idServiceSituation;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ServicesSituations other = (ServicesSituations) obj;
		if (idServiceSituation == null) {
			if (other.idServiceSituation != null)
				return false;
		} else if (!idServiceSituation.equals(other.idServiceSituation))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return cdServiceSituation;
	}
}

